<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎</title>
    <th:block th:include="include::header" />
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="type" class="layui-form-label">
                    <span class="x-red">*</span>设备类型</label>
                <div class="layui-input-inline">
                    <input type="text" id="type" name="type" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="test1" class="layui-form-label">
                    添加时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="begin" class="layui-input" id="test1" placeholder="yyyy-MM-dd HH:mm:ss"></div>
            </div>
            <div class="layui-form-item">
                <label for="test2" class="layui-form-label">
                    修改时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="end" class="layui-input" id="test2" placeholder="yyyy-MM-dd HH:mm:ss"></div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="production" class="layui-form-label">
                    <span class="x-red">*</span>评价</label>
                <div class="layui-input-inline">
                    <input type="text" id="production" name="production" required="" lay-verify="number"
                           autocomplete="off" class="layui-input"></div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer', 'jquery'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(add)',
            function (data) {
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    url:"/work/add",
                    type: "POST",
                    data:data.field,
                    success(res){
                        if(res.success){
                            layer.alert("添加成功", {
                                    icon: 6
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }else{
                            layer.msg(res.msg)
                        }
                    }
                })
                return false;
            });
    });</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#test1'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#test2'
            ,type: 'datetime'
        });
        //前后若干天可选，这里以7天为例
        laydate.render({
            elem: '#test-limit2'
            ,min: -7
            ,max: 7
        });
        //同时绑定多个
        lay('.test-item').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
            });
        });
    });
</script>
</body>

</html>